import {promisify} from 'util'
import childProcess from 'child_process'

const execFile = promisify(childProcess.execFile)

async function remoteGitTags(repoUrl){
    const {stdout}=await execFile('git',['ls-remote','--tags',repoUrl])
    console.log(stdout)
    const tags=new Map()
    for(const line of stdout.trim().split('\n')){
        const [hash,tagReference] = line.split('\t')

        const tagName = tagReference
                                .replace(/^refs\/tags\//,'')
                                .replace(/\^{}$/,'')
        tags.set(tagName,hash)
    }
    return tags
}

try {
    console.log(remoteGitTags('https://github.com/lxchuan12/blog.git'))
} catch (error) {
    
}

